package com.vanke.devops.domain.manager.docker.extend.exec;

import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.core.util.FiltersEncoder;
import com.github.dockerjava.jaxrs.AbstrSyncDockerCmdExec;
import com.vanke.devops.domain.manager.docker.extend.command.ListNodesCmd;
import com.vanke.devops.domain.manager.docker.extend.model.Node;
import com.vanke.devops.domain.manager.docker.extend.model.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import java.util.List;

import static com.google.common.net.UrlEscapers.urlPathSegmentEscaper;

/**
 * @author 陈景阳
 * @since 2018/6/8
 */
public class ListNodesCmdExec extends AbstrSyncDockerCmdExec<ListNodesCmd,List<Node>> implements ListNodesCmd.Exec{

    private static final Logger LOGGER = LoggerFactory.getLogger(ListNodesCmdExec.class);

    public ListNodesCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) {
        super(baseResource, dockerClientConfig);
    }

    @Override
    protected List<Node> execute(ListNodesCmd command) {
        WebTarget webTarget = getBaseResource().path("/nodes");
        LOGGER.trace("GET: {}", webTarget);

        List<Node> nodes = webTarget.request()
                .accept(MediaType.APPLICATION_JSON).get(new GenericType<List<Node>>() {
                });
        LOGGER.trace("Response: {}", nodes);
        return nodes;
    }
}
